package com.kun.rental.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kun.rental.entity.Customer;
import com.kun.rental.service.ICustomerService;
import com.kun.rental.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 * 客户管理
 *
 * @author ikun
 * @since 2024-07-04
 */
@RestController
@RequestMapping("/rental/customer")
public class CustomerController {

    @Autowired
    private ICustomerService customerService;

    /**
     * 分页查询客户
     * @param start
     * @param size
     * @param customer
     * @return
     */
    @PostMapping("/search/{start}/{size}")
    private Result searchByPage(@PathVariable int start,
                                @PathVariable int size,
                                @RequestBody Customer customer){
        Page<Customer> page = new Page<>(start, size);
        return Result.success(customerService.searchByPage(page, customer));

    }


    /**
     * 新增客户
     * @param customer
     * @return
     */
    @PostMapping("/save")
    private Result save(@RequestBody Customer customer){
        return customerService.save(customer) ? Result.success(customer.getId()) : Result.fail();
    }


    /**
     * 修改客户
     * @param customer
     * @return
     */
    @PutMapping("/update")
    private Result update(@RequestBody Customer customer){
        return customerService.updateById(customer) ? Result.success() : Result.fail();
    }


    /**
     * 删除客户
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/{ids}")
    private Result delete(@PathVariable String ids){
        return customerService.delete(ids) ? Result.success() : Result.fail();
    }


    /**
     * 根据手机号查询客户
     * @param customer
     * @return
     */
    @PostMapping("/selectCustomerByTelephone")
    public Result selectCustomerByTelephone(@RequestBody Customer customer){
        return Result.success(customerService.selectByCustomerByTelephone(customer));
    }


}
